Как конвертировать DOCX с изменениями в формат PDF с помощью C# и .NET


Включение Track Changes дает Вам и Вашим коллегам возможность вносить изменения, которые легко заметить. Изменения подобны предложениям, которые вы можете просмотреть, а затем удалить их или сделать постоянными.

Этот пример кода показывает, как Вы можете принять или отклонить изменения.

Загрузите файл примера: example.docx

Загрузите полученный файл: result.pdf

Полный код

using SautinSoft.Document;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            Revision();
        }
        /// <summary>
        /// Shows how to work with revisions.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/revision-track-changes-net-csharp-vb.php
        /// </remarks>
        static void Revision()
        {
            DocumentCore dc = DocumentCore.Load(@"..\..\..\example.docx");
            
            // Accepting the deletion revision will assimilate it into the paragraph's inlines and remove them from the collection.
            dc.Revisions[0].Accept();

            // The second insertion revision is now at index 0, which we can reject to ignore and discard it.
            dc.Revisions[0].Reject();

            // Now we have two revisions in the list items, we accept them all.
            dc.Revisions.AcceptAll();

            dc.Save(@"result.pdf");
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(@"result.pdf") { UseShellExecute = true });
        }
    }
}

Download

Imports SautinSoft.Document

Namespace Example
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			Revision()
		End Sub
                ''' Get your free 30-day key here:   
                ''' https://sautinsoft.com/start-for-free/
		''' <summary>
		''' Shows how to work with revisions.
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/revision-track-changes-net-csharp-vb.php
		''' </remarks>
		Private Shared Sub Revision()
			Dim dc As DocumentCore = DocumentCore.Load("..\..\..\example.docx")

			' Accepting the deletion revision will assimilate it into the paragraph's inlines and remove them from the collection.
			dc.Revisions(0).Accept()

			' The second insertion revision is now at index 0, which we can reject to ignore and discard it.
			dc.Revisions(0).Reject()

			' Now we have two revisions in the list items, we accept them all.
			dc.Revisions.AcceptAll()

			dc.Save("result.pdf")
			System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("result.pdf") With {.UseShellExecute = True})
		End Sub
	End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.